package com.base.video;

import android.content.Context;
import android.content.res.Configuration;
import android.view.View;
import android.view.inputmethod.InputMethodManager;

import com.base.commonlib.base.CBaseMvpFragment;
import com.base.commonlib.base.presenter.BasePresenter;
import com.base.video.java.MediaPlayerManager;

/**
 * Created by weikailiang on 2020/2/21.
 */

public abstract class  CBaseVideoBarFragment<H extends BasePresenter> extends CBaseMvpFragment<H>{

    @Override
    public boolean onBackPressedSupport() {
        if (MediaPlayerManager.instance().backPress()) {
            return false;
        }
        return super.onBackPressedSupport();
    }

    @Override
    public void onPause() {
        super.onPause();
        hideSoftInput();
        MediaPlayerManager.instance().pause();
    }


    @Override
    public void onDestroy() {
        super.onDestroy();
        MediaPlayerManager.instance().releasePlayerAndView(mContext);
    }

    //显示软键盘
    public void showSoftInput(View view) {
        InputMethodManager imm = (InputMethodManager)mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
        if (imm != null) {
            view.requestFocus();
            imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
        }
    }

    //收起软键盘
    public void hideSoftInput() {
        InputMethodManager imm = (InputMethodManager)mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
        if (imm != null) {
            imm.hideSoftInputFromWindow(_mActivity.getWindow().getDecorView().getWindowToken(), 0);
        }
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        hideSoftInput();
    }
}
